﻿Partial Public Class DynamicResourceDemo

    Private _bolIsCool As Boolean = False

    Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnChange.Click
        SetResources()
    End Sub

    Private Sub DynamicResourceDemo_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        SetResources()
    End Sub

    Private Sub SetResources()

        If _bolIsCool Then
            Me.Resources.Item("brushTitle") = New SolidColorBrush(Colors.Blue)
            Me.Resources.Item("brushText") = New SolidColorBrush(Colors.SteelBlue)
        Else
            Me.Resources.Item("brushTitle") = New SolidColorBrush(Colors.Red)
            Me.Resources.Item("brushText") = New SolidColorBrush(Colors.Maroon)
        End If

        _bolIsCool = Not _bolIsCool
    End Sub

    Private Sub btnChangeBottom_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnChangeBottom.Click
        Dim obj As SolidColorBrush = Me.FindResource("testBrushResource")
        obj.Color = Colors.Green
    End Sub

    Private Sub btnSwapBottom_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSwapBottom.Click
        Me.Resources.Remove("testBrushResource")
        Me.Resources.Add("testBrushResource", New SolidColorBrush(Colors.Blue))
    End Sub

End Class
